home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / CATPRC.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  41.8 KB  |  1,270 lines

  1. rem 
  2. rem $Header: catprc.sql 7020100.1 94/09/23 22:14:25 cli Generic<base> $ prctrg.sql 
  3. rem 
  4. Rem Copyright (c) 1990 by Oracle Corporation
  5. Rem NAME
  6. Rem    CATPRC.SQL
  7. Rem FUNCTION
  8. Rem    Creates data dictionary views for stored procedures and triggers. 
  9. Rem NOTES
  10. Rem    Must be run while connected to sys or internal.
  11. Rem
  12. Rem MODIFIED
  13. Rem     wmaimone   05/26/94 -  #186155 add public synoyms for dba_
  14. Rem     jbellemo   05/09/94 -  merge changes from branch 1.2.710.2
  15. Rem     jbellemo   12/17/93 -  merge changes from branch 1.2.710.1
  16. Rem     jbellemo   04/27/94 -  #199905: fix security in ALL_ERRORS
  17. Rem     jbellemo   11/09/93 -  #170173: change uid to userenv schemaid
  18. Rem     tpystyne   10/28/92 -  use create or replace view 
  19. Rem     glumpkin   10/20/92 -  Renamed from PRCTRG.SQL 
  20. Rem     mmoore     10/15/92 - #(131033) add trigger column views for marketing 
  21. Rem     mmoore     09/29/92 - #(131033) add more info to the triggers view 
  22. Rem     jwijaya    08/17/92 -  add sequence to error$ 
  23. Rem     jwijaya    07/17/92 -  remove database link owner from name 
  24. Rem     mmoore     06/03/92 - #(111923) change trigger view names 
  25. Rem     mmoore     06/02/92 - #(96526) remove v$enabledroles 
  26. Rem     mroberts   06/01/92 -  change privileges for all_errors view 
  27. Rem     rkooi      04/15/92 -  test tools 
  28. Rem     rkooi      01/18/92 -  add synonym 
  29. Rem     rkooi      01/18/92 -  add object_sizes views 
  30. Rem     rkooi      01/10/92 -  synchronize with catalog.sql 
  31. Rem     rkooi      12/23/91 -  testing 
  32. Rem     rkooi      10/20/91 -  add public_dependency 
  33. Rem     jwijaya    07/14/91 -  remove LINKNAME IS NULL 
  34. Rem     rkooi      05/22/91 -  get rid of _object in some catalog names 
  35. Rem     rkooi      05/22/91 - change *_references to *_dependencies
  36. Rem     rkooi      05/05/91 - fix up permissions on all* cats 
  37. Rem     jwijaya    04/12/91 - remove LINKNAME IS NULL 
  38. Rem     rkooi      03/29/91 - add views for pcode & diana 
  39. Rem     Kooi       03/12/91 - Creation
  40. Rem     Kooi       03/12/91 - Creation
  41. Rem
  42.  
  43.  
  44. remark
  45. remark    FAMILY "ERRORS"
  46. remark    Errors for stored objects - currently these are
  47. remark    PL/SQL packages, package bodies, procedures and functions.
  48. remark
  49.  
  50. create or replace view USER_ERRORS
  51. (NAME, TYPE, SEQUENCE, LINE, POSITION, TEXT)
  52. as
  53. select o.name,
  54. decode(o.type, 4, 'VIEW', 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  55. 11, 'PACKAGE BODY', 'UNDEFINED'),
  56. e.sequence, e.line, e.position, e.text
  57. from sys.obj$ o, sys.error$ e
  58. where o.obj# = e.obj#
  59.   and o.type in (4, 7, 8, 9, 11)
  60.   and o.owner# = userenv('SCHEMAID')
  61. /
  62. comment on table USER_ERRORS is
  63. 'Current errors on stored objects owned by the user'
  64. /
  65. comment on column USER_ERRORS.NAME is
  66. 'Name of the object'
  67. /
  68. comment on column USER_ERRORS.TYPE is
  69. 'Type of object: "VIEW", "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  70. /
  71. comment on column USER_ERRORS.SEQUENCE is
  72. 'Sequence number used for ordering purposes'
  73. /
  74. comment on column USER_ERRORS.LINE is
  75. 'Line number at which this error occurs'
  76. /
  77. comment on column USER_ERRORS.POSITION is
  78. 'Position in the line at which this error occurs'
  79. /
  80. comment on column USER_ERRORS.TEXT is
  81. 'Text of the error'
  82. /
  83. drop public synonym USER_ERRORS
  84. /
  85. create public synonym USER_ERRORS for USER_ERRORS
  86. /
  87. grant select on USER_ERRORS to public with grant option
  88. /
  89.  
  90. remark
  91. remark  User is allowed to see errors on any object that they own
  92. remark  or could have created.
  93. remark
  94.  
  95. create or replace view ALL_ERRORS
  96. (OWNER, NAME, TYPE, SEQUENCE, LINE, POSITION, TEXT)
  97. as
  98. select u.name, o.name,
  99. decode(o.type, 4, 'VIEW', 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  100. 11, 'PACKAGE BODY', 'UNDEFINED'),
  101. e.sequence, e.line, e.position, e.text
  102. from sys.obj$ o, sys.error$ e, sys.user$ u
  103. where o.obj# = e.obj#
  104.   and o.owner# = u.user#
  105.   and o.type in (4, 7, 8, 9, 11)
  106.   and
  107.   (
  108.     o.owner# in (userenv('SCHEMAID'), 1 /* PUBLIC */)
  109.     or
  110.     (
  111.       (
  112.          (
  113.           (o.type = 7 or o.type = 8 or o.type = 9)
  114.           and
  115.           o.obj# in (select obj# from sys.objauth$
  116.                      where grantee# in (select kzsrorol from x$kzsro)
  117.                        and privilege#  = 12 /* EXECUTE */)
  118.         )
  119.         or
  120.         (
  121.           o.type = 4
  122.           and
  123.           o.obj# in (select obj# from sys.objauth$
  124.                      where grantee# in (select kzsrorol from x$kzsro)
  125.                        and privilege# in (3 /* DELETE */,   6 /* INSERT */,
  126.                                             7 /* LOCK */,     9 /* SELECT */,
  127.                                           10 /* UPDATE */))
  128.         )
  129.         or
  130.         exists
  131.         (
  132.           select null from sys.sysauth$
  133.           where grantee# in (select kzsrorol from x$kzsro)
  134.           and
  135.           (
  136.             (
  137.               /* procedure */
  138.               (o.type = 7 or o.type = 8 or o.type = 9)
  139.               and
  140.               (
  141.                 privilege# = -144 /* EXECUTE ANY PROCEDURE */
  142.                 or
  143.                 privilege# = -141 /* CREATE ANY PROCEDURE */
  144.               )
  145.             )
  146.         or
  147.             (
  148.               /* package body */
  149.               o.type = 11 and
  150.               privilege# = -141 /* CREATE ANY PROCEDURE */
  151.             )
  152.             or
  153.             (
  154.               /* view */
  155.               o.type = 4
  156.               and
  157.               (
  158.                 privilege# in     ( -91 /* CREATE ANY VIEW */,
  159.                                     -45 /* LOCK ANY TABLE */,
  160.                                     -47 /* SELECT ANY TABLE */,
  161.                                     -48 /* INSERT ANY TABLE */,
  162.                                     -49 /* UPDATE ANY TABLE */,
  163.                                     -50 /* DELETE ANY TABLE */)
  164.               )
  165.             )
  166.           )
  167.         )
  168.       )
  169.     )
  170.   )
  171. /
  172. comment on table ALL_ERRORS is
  173. 'Current errors on stored objects that user is allowed to create'
  174. /
  175. comment on column ALL_ERRORS.OWNER is
  176. 'Owner of the object'
  177. /
  178. comment on column ALL_ERRORS.NAME is
  179. 'Name of the object'
  180. /
  181. comment on column ALL_ERRORS.TYPE is
  182. 'Type of object: "VIEW", "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  183. /
  184. comment on column ALL_ERRORS.SEQUENCE is
  185. 'Sequence number used for ordering purposes'
  186. /
  187. comment on column ALL_ERRORS.LINE is
  188. 'Line number at which this error occurs'
  189. /
  190. comment on column ALL_ERRORS.POSITION is
  191. 'Position in the line at which this error occurs'
  192. /
  193. comment on column ALL_ERRORS.TEXT is
  194. 'Text of the error'
  195. /
  196. drop public synonym ALL_ERRORS
  197. /
  198. create public synonym ALL_ERRORS for ALL_ERRORS
  199. /
  200. grant select on ALL_ERRORS to public with grant option
  201. /
  202.  
  203. create or replace view DBA_ERRORS
  204. (OWNER, NAME, TYPE, SEQUENCE, LINE, POSITION, TEXT)
  205. as
  206. select u.name, o.name,
  207. decode(o.type, 4, 'VIEW', 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  208. 11, 'PACKAGE BODY', 'UNDEFINED'),
  209. e.sequence, e.line, e.position, e.text
  210. from sys.obj$ o, sys.error$ e, sys.user$ u
  211. where o.obj# = e.obj#
  212.   and o.owner# = u.user#
  213.   and o.type in (4, 7, 8, 9, 11)
  214. /
  215. drop public synonym DBA_ERRORS
  216. /
  217. create public synonym DBA_ERRORS for DBA_ERRORS
  218. /
  219. comment on table DBA_ERRORS is
  220. 'Current errors on all stored objects in the database'
  221. /
  222. comment on column DBA_ERRORS.NAME is
  223. 'Name of the object'
  224. /
  225. comment on column DBA_ERRORS.TYPE is
  226. 'Type of object: "VIEW", "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  227. /
  228. comment on column DBA_ERRORS.SEQUENCE is
  229. 'Sequence number used for ordering purposes'
  230. /
  231. comment on column DBA_ERRORS.LINE is
  232. 'Line number at which this error occurs'
  233. /
  234. comment on column DBA_ERRORS.POSITION is
  235. 'Position in the line at which this error occurs'
  236. /
  237. comment on column DBA_ERRORS.TEXT is
  238. 'Text of the error'
  239. /
  240.  
  241.  
  242. remark
  243. remark    FAMILY "SOURCE"
  244. remark    SOURCE for stored objects - currently these are 
  245. remark    PL/SQL packages, package bodies, procedures and functions.
  246. remark
  247.  
  248. create or replace view USER_SOURCE
  249. (NAME, TYPE, LINE, TEXT)
  250. as
  251. select o.name,
  252. decode(o.type, 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  253. 11, 'PACKAGE BODY', 'UNDEFINED'),
  254. s.line, s.source
  255. from sys.obj$ o, sys.source$ s
  256. where o.obj# = s.obj#
  257.   and o.type in (7, 8, 9, 11)
  258.   and o.owner# = userenv('SCHEMAID')
  259. /
  260. comment on table USER_SOURCE is
  261. 'Source of stored objects accessible to the user'
  262. /
  263. comment on column USER_SOURCE.NAME is
  264. 'Name of the object'
  265. /
  266. comment on column USER_SOURCE.TYPE is
  267. 'Type of the object: "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  268. /
  269. comment on column USER_SOURCE.LINE is
  270. 'Line number of this line of source'
  271. /
  272. comment on column USER_SOURCE.TEXT is
  273. 'Source text'
  274. /
  275. drop public synonym USER_SOURCE
  276. /
  277. create public synonym USER_SOURCE for USER_SOURCE
  278. /
  279. grant select on USER_SOURCE to public with grant option
  280. /
  281.  
  282. create or replace view ALL_SOURCE
  283. (OWNER, NAME, TYPE, LINE, TEXT)
  284. as
  285. select u.name, o.name,
  286. decode(o.type, 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  287. 11, 'PACKAGE BODY', 'UNDEFINED'),
  288. s.line, s.source
  289. from sys.obj$ o, sys.source$ s, sys.user$ u
  290. where o.obj# = s.obj#
  291.   and o.owner# = u.user#
  292.   and o.type in (7, 8, 9, 11)
  293.   and
  294.   (
  295.     o.owner# in (userenv('SCHEMAID'), 1 /* PUBLIC */)
  296.     or
  297.     (
  298.       (
  299.          (
  300.           (o.type = 7 or o.type = 8 or o.type = 9)
  301.           and
  302.           o.obj# in (select obj# from sys.objauth$
  303.                      where grantee# in (select kzsrorol from x$kzsro)
  304.                        and privilege#  = 12 /* EXECUTE */)
  305.         )
  306.         or
  307.         exists
  308.         (
  309.           select null from sys.sysauth$
  310.           where grantee# in (select kzsrorol from x$kzsro)
  311.           and
  312.           (
  313.             (
  314.               /* procedure */
  315.               (o.type = 7 or o.type = 8 or o.type = 9)
  316.               and
  317.               (
  318.                 privilege# = -144 /* EXECUTE ANY PROCEDURE */
  319.                 or
  320.                 privilege# = -141 /* CREATE ANY PROCEDURE */
  321.               )
  322.             )
  323.         or
  324.             (
  325.               /* package body */
  326.               o.type = 11 and
  327.               privilege# = -141 /* CREATE ANY PROCEDURE */
  328.             )
  329.           )
  330.         )
  331.       )
  332.     )
  333.   )
  334. /
  335. comment on table ALL_SOURCE is
  336. 'Current source on stored objects that user is allowed to create'
  337. /
  338. comment on column ALL_SOURCE.OWNER is
  339. 'Owner of the object'
  340. /
  341. comment on column ALL_SOURCE.NAME is
  342. 'Name of the object'
  343. /
  344. comment on column ALL_SOURCE.TYPE is
  345. 'Type of the object: "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  346. /
  347. comment on column ALL_SOURCE.LINE is
  348. 'Line number of this line of source'
  349. /
  350. comment on column ALL_SOURCE.TEXT is
  351. 'Source text'
  352. /
  353. drop public synonym ALL_SOURCE
  354. /
  355. create public synonym ALL_SOURCE for ALL_SOURCE
  356. /
  357. grant select on ALL_SOURCE to public with grant option
  358. /
  359.  
  360. create or replace view DBA_SOURCE
  361. (OWNER, NAME, TYPE, LINE, TEXT)
  362. as
  363. select u.name, o.name,
  364. decode(o.type, 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  365. 11, 'PACKAGE BODY', 'UNDEFINED'),
  366. s.line, s.source
  367. from sys.obj$ o, sys.source$ s, sys.user$ u
  368. where o.obj# = s.obj#
  369.   and o.owner# = u.user#
  370.   and o.type in (7, 8, 9, 11)
  371. /
  372. drop public synonym DBA_SOURCE
  373. /
  374. create public synonym DBA_SOURCE for DBA_SOURCE
  375. /
  376. comment on table DBA_SOURCE is
  377. 'Source of all stored objects in the database'
  378. /
  379. comment on column DBA_SOURCE.NAME is
  380. 'Name of the object'
  381. /
  382. comment on column DBA_SOURCE.TYPE is
  383. 'Type of the object: "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  384. /
  385. comment on column DBA_SOURCE.LINE is
  386. 'Line number of this line of source'
  387. /
  388. comment on column DBA_SOURCE.TEXT is
  389. 'Source text'
  390. /
  391.  
  392. remark
  393. remark    FAMILY "TRIGGERS"
  394. remark    Database trigger definitions.
  395. remark    This family has no "ALL" member.
  396. remark
  397.  
  398. create or replace view USER_TRIGGERS
  399. (TRIGGER_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, TABLE_NAME, 
  400.  REFERENCING_NAMES, WHEN_CLAUSE, STATUS, DESCRIPTION, TRIGGER_BODY)
  401. as
  402. select trigobj.name,
  403. decode(t.type, 0, 'BEFORE STATEMENT',
  404.                1, 'BEFORE EACH ROW',
  405.                2, 'AFTER STATEMENT',
  406.                3, 'AFTER EACH ROW', 'UNDEFINED'),
  407. decode(t.insert$*100 + t.update$*10 + t.delete$,
  408.                  100, 'INSERT',
  409.                  010, 'UPDATE',
  410.                  001, 'DELETE',
  411.                  110, 'INSERT OR UPDATE',
  412.                  101, 'INSERT OR DELETE',
  413.                  011, 'UPDATE OR DELETE',
  414.                  111, 'INSERT OR UPDATE OR DELETE', 'ERROR'),
  415. u.name, tabobj.name, 
  416. 'REFERENCING NEW AS '||t.refnewname||' OLD AS '||t.refoldname,
  417. t.whenclause,decode(t.enabled, 0, 'DISABLED', 1, 'ENABLED', 'ERROR'),
  418. t.definition,t.action
  419. from sys.obj$ trigobj, sys.obj$ tabobj, sys.trigger$ t, sys.user$ u
  420. where trigobj.obj#   = t.obj#
  421.   and tabobj.obj#    = t.baseobject
  422.   and trigobj.owner# = userenv('SCHEMAID')
  423.   and tabobj.owner#  = u.user#
  424. /
  425. comment on table USER_TRIGGERS is
  426. 'Triggers owned by the user'
  427. /
  428. comment on column USER_TRIGGERS.TRIGGER_NAME is
  429. 'Name of the trigger'
  430. /
  431. comment on column USER_TRIGGERS.TRIGGER_TYPE is
  432. 'Type of the trigger (when it fires) - BEFORE/AFTER and STATEMENT/ROW'
  433. /
  434. comment on column USER_TRIGGERS.TRIGGERING_EVENT is
  435. 'Statement that will fire the trigger - INSERT, UPDATE and/or DELETE'
  436. /
  437. comment on column USER_TRIGGERS.TABLE_OWNER is
  438. 'Owner of the table that this trigger is associated with'
  439. /
  440. comment on column USER_TRIGGERS.TABLE_NAME is
  441. 'Name of the table that this trigger is associated with'
  442. /
  443. comment on column USER_TRIGGERS.REFERENCING_NAMES is
  444. 'Names used for referencing to OLD and NEW values within the trigger'
  445. /
  446. comment on column USER_TRIGGERS.WHEN_CLAUSE is
  447. 'WHEN clause must evaluate to true in order for triggering body to execute'
  448. /
  449. comment on column USER_TRIGGERS.STATUS is
  450. 'If DISABLED then trigger will not fire'
  451. /
  452. comment on column USER_TRIGGERS.DESCRIPTION is
  453. 'Trigger description, useful for re-creating trigger creation statement'
  454. /
  455. comment on column USER_TRIGGERS.TRIGGER_BODY is
  456. 'Action taken by this trigger when it fires'
  457. /
  458. drop public synonym USER_TRIGGERS
  459. /
  460. create public synonym USER_TRIGGERS for USER_TRIGGERS
  461. /
  462. grant select on USER_TRIGGERS to public with grant option
  463. /
  464.  
  465. create or replace view ALL_TRIGGERS
  466. (OWNER, TRIGGER_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, TABLE_NAME,
  467.  REFERENCING_NAMES, WHEN_CLAUSE, STATUS, DESCRIPTION, TRIGGER_BODY)
  468. as
  469. select triguser.name, trigobj.name,
  470. decode(t.type, 0, 'BEFORE STATEMENT',
  471.                1, 'BEFORE EACH ROW',
  472.                2, 'AFTER STATEMENT',
  473.                3, 'AFTER EACH ROW', 'UNDEFINED'),
  474. decode(t.insert$*100 + t.update$*10 + t.delete$,
  475.                  100, 'INSERT',
  476.                  010, 'UPDATE',
  477.                  001, 'DELETE',
  478.                  110, 'INSERT OR UPDATE',
  479.                  101, 'INSERT OR DELETE',
  480.                  011, 'UPDATE OR DELETE',
  481.                  111, 'INSERT OR UPDATE OR DELETE', 'ERROR'),
  482. tabuser.name, tabobj.name, 
  483. 'REFERENCING NEW AS '||t.refnewname||' OLD AS '||t.refoldname,
  484. t.whenclause,decode(t.enabled, 0, 'DISABLED', 1, 'ENABLED', 'ERROR'),
  485. t.definition,t.action
  486. from sys.obj$ trigobj, sys.obj$ tabobj, sys.trigger$ t, sys.user$ tabuser,
  487.      sys.user$ triguser
  488. where trigobj.obj#   = t.obj#
  489.   and tabobj.obj#    = t.baseobject
  490.   and trigobj.owner# = triguser.user#
  491.   and tabobj.owner#  = tabuser.user#
  492.   and
  493.   (
  494.     trigobj.owner# = userenv('SCHEMAID') or tabobj.owner# = userenv('SCHEMAID')
  495.     or
  496.     exists (select null from sys.sysauth$
  497.              where grantee# in (select kzsrorol from x$kzsro)
  498.                and privilege# = -152 /* CREATE ANY TRIGGER */)
  499.   )
  500. /
  501. comment on table ALL_TRIGGERS is
  502. 'Triggers accessible to the current user'
  503. /
  504. comment on column ALL_TRIGGERS.OWNER is
  505. 'Owner of the trigger'
  506. /
  507. comment on column ALL_TRIGGERS.TRIGGER_NAME is
  508. 'Name of the trigger'
  509. /
  510. comment on column ALL_TRIGGERS.TRIGGER_TYPE is
  511. 'When the trigger fires - BEFORE/AFTER and STATEMENT/ROW'
  512. /
  513. comment on column ALL_TRIGGERS.TRIGGERING_EVENT is
  514. 'Statement that will fire the trigger - INSERT, UPDATE and/or DELETE'
  515. /
  516. comment on column ALL_TRIGGERS.TABLE_OWNER is
  517. 'Owner of the table that this trigger is associated with'
  518. /
  519. comment on column ALL_TRIGGERS.TABLE_NAME is
  520. 'Name of the table that this trigger is associated with'
  521. /
  522. comment on column ALL_TRIGGERS.REFERENCING_NAMES is
  523. 'Names used for referencing to OLD and NEW values within the trigger'
  524. /
  525. comment on column ALL_TRIGGERS.WHEN_CLAUSE is
  526. 'WHEN clause must evaluate to true in order for triggering body to execute'
  527. /
  528. comment on column ALL_TRIGGERS.STATUS is
  529. 'If DISABLED then trigger will not fire'
  530. /
  531. comment on column ALL_TRIGGERS.DESCRIPTION is
  532. 'Trigger description, useful for re-creating trigger creation statement'
  533. /
  534. comment on column ALL_TRIGGERS.TRIGGER_BODY is
  535. 'Action taken by this trigger when it fires'
  536. /
  537. drop public synonym ALL_TRIGGERS
  538. /
  539. create public synonym ALL_TRIGGERS for ALL_TRIGGERS
  540. /
  541. grant select on ALL_TRIGGERS to public with grant option
  542. /
  543.  
  544. create or replace view DBA_TRIGGERS
  545. (OWNER, TRIGGER_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, TABLE_NAME,
  546.  REFERENCING_NAMES, WHEN_CLAUSE, STATUS, DESCRIPTION, TRIGGER_BODY)
  547. as
  548. select trigusr.name, trigobj.name,
  549. decode(t.type, 0, 'BEFORE STATEMENT',
  550.                1, 'BEFORE EACH ROW',
  551.                2, 'AFTER STATEMENT',
  552.                3, 'AFTER EACH ROW', 'UNDEFINED'),
  553. decode(t.insert$*100 + t.update$*10 + t.delete$,
  554.                  100, 'INSERT',
  555.                  010, 'UPDATE',
  556.                  001, 'DELETE',
  557.                  110, 'INSERT OR UPDATE',
  558.                  101, 'INSERT OR DELETE',
  559.                  011, 'UPDATE OR DELETE',
  560.                  111, 'INSERT OR UPDATE OR DELETE', 'ERROR'),
  561. tabusr.name, tabobj.name, 
  562. 'REFERENCING NEW AS '||t.refnewname||' OLD AS '||t.refoldname,
  563. t.whenclause,decode(t.enabled, 0, 'DISABLED', 1, 'ENABLED', 'ERROR'),
  564. t.definition,t.action
  565. from sys.obj$ trigobj, sys.obj$ tabobj, sys.trigger$ t,
  566.      sys.user$ tabusr, sys.user$ trigusr
  567. where trigobj.obj#   = t.obj#
  568.   and tabobj.obj#    = t.baseobject
  569.   and tabobj.owner#  = tabusr.user#
  570.   and trigobj.owner# = trigusr.user#
  571. /
  572. drop public synonym DBA_TRIGGERS
  573. /
  574. create public synonym DBA_TRIGGERS for DBA_TRIGGERS
  575. /
  576. comment on table DBA_TRIGGERS is
  577. 'All triggers in the database'
  578. /
  579. comment on column DBA_TRIGGERS.OWNER is
  580. 'Owner of the trigger'
  581. /
  582. comment on column DBA_TRIGGERS.TRIGGER_NAME is
  583. 'Name of the trigger'
  584. /
  585. comment on column DBA_TRIGGERS.TRIGGER_TYPE is
  586. 'When the trigger fires - BEFORE/AFTER and STATEMENT/ROW'
  587. /
  588. comment on column DBA_TRIGGERS.TRIGGERING_EVENT is
  589. 'Statement that will fire the trigger - INSERT, UPDATE and/or DELETE'
  590. /
  591. comment on column DBA_TRIGGERS.TABLE_OWNER is
  592. 'Owner of the table that this trigger is associated with'
  593. /
  594. comment on column DBA_TRIGGERS.TABLE_NAME is
  595. 'Name of the table that this trigger is associated with'
  596. /
  597. comment on column DBA_TRIGGERS.REFERENCING_NAMES is
  598. 'Names used for referencing to OLD and NEW values within the trigger'
  599. /
  600. comment on column DBA_TRIGGERS.WHEN_CLAUSE is
  601. 'WHEN clause must evaluate to true in order for triggering body to execute'
  602. /
  603. comment on column DBA_TRIGGERS.STATUS is
  604. 'If DISABLED then trigger will not fire'
  605. /
  606. comment on column DBA_TRIGGERS.DESCRIPTION is
  607. 'Trigger description, useful for re-creating trigger creation statement'
  608. /
  609. comment on column DBA_TRIGGERS.TRIGGER_BODY is
  610. 'Action taken by this trigger when it fires'
  611. /
  612.  
  613. remark
  614. remark    USER_TRIGGER_COLS shows usage of columns in triggers owned by the
  615. remark    current user or in triggers on tables owned by the current user
  616. remark
  617.  
  618. create or replace view USER_TRIGGER_COLS
  619. (TRIGGER_OWNER, TRIGGER_NAME, TABLE_OWNER, TABLE_NAME, COLUMN_NAME,
  620.     COLUMN_LIST, COLUMN_USAGE)
  621. as
  622. select /*+ ORDERED NOCOST */ u.name, o.name, u2.name, o2.name, c.name,
  623.    max(decode(tc.type,0,'YES','NO')) COLUMN_LIST,
  624.    decode(sum(decode(tc.type, 5,  1, -- one occurrence of new in
  625.                               6,  2, -- one occurrence of old in
  626.                               9,  4, -- one occurrence of new out
  627.                              10,  8, -- one occurrence of old out (impossible)
  628.                              13,  5, -- one occurrence of new in out
  629.                              14, 10, -- one occurrence of old in out (imp.)
  630.                               null)
  631.                 ), -- result in the following combinations across occurrences
  632.            1, 'NEW IN',
  633.            2, 'OLD IN',
  634.            3, 'NEW IN OLD IN',
  635.            4, 'NEW OUT',
  636.            5, 'NEW IN OUT',
  637.            6, 'NEW OUT OLD IN',
  638.            7, 'NEW IN OUT OLD IN',
  639.           'NONE')
  640. from sys.trigger$ t, sys.obj$ o, sys.user$ u, sys.user$ u2,
  641.      sys.col$ c, sys.obj$ o2, sys.triggercol$ tc
  642. where t.obj# = tc.obj#        -- find corresponding trigger definition
  643.   and o.obj# = t.obj#        --    and corresponding trigger name
  644.   and c.obj# = t.baseobject     -- and corresponding row in COL$ of
  645.   and c.col# = tc.col#        --    the referenced column
  646.   and o2.obj# = t.baseobject    -- and name of the table containing the trigger
  647.   and u2.user# = o2.owner#    -- and name of the user who owns the table
  648.   and u.user# = o.owner#    -- and name of user who owns the trigger
  649.   and ((o.owner# = userenv('SCHEMAID') and u.user# = userenv('SCHEMAID')) -- triggers owned by the current user
  650.       or
  651.        (o2.owner# = userenv('SCHEMAID') and u2.user# = userenv('SCHEMAID'))) -- on the current user's tables
  652. group by u.name, o.name, u2.name, o2.name, c.name
  653. /
  654. comment on table USER_TRIGGER_COLS is
  655. 'Column usage in user''s triggers'
  656. /
  657. comment on column USER_TRIGGER_COLS.TRIGGER_OWNER is
  658. 'Owner of the trigger'
  659. /
  660. comment on column USER_TRIGGER_COLS.TRIGGER_NAME is
  661. 'Name of the trigger'
  662. /
  663. comment on column USER_TRIGGER_COLS.TABLE_OWNER is
  664. 'Owner of the table'
  665. /
  666. comment on column USER_TRIGGER_COLS.TABLE_NAME is
  667. 'Name of the table on which the trigger is defined'
  668. /
  669. comment on column USER_TRIGGER_COLS.COLUMN_NAME is
  670. 'Name of the column used in trigger definition'
  671. /
  672. comment on column USER_TRIGGER_COLS.COLUMN_LIST is
  673. 'Is column specified in UPDATE OF clause?'
  674. /
  675. comment on column USER_TRIGGER_COLS.COLUMN_USAGE is
  676. 'Usage of column within trigger body'
  677. /
  678. drop public synonym USER_TRIGGER_COLS
  679. /
  680. create public synonym USER_TRIGGER_COLS for USER_TRIGGER_COLS
  681. /
  682. grant select on USER_TRIGGER_COLS to public
  683. /
  684. remark
  685. remark    ALL_TRIGGER_COLS shows usage of columns in triggers owned by the
  686. remark    current user or in triggers on tables owned by the current user
  687. remark    or on all triggers if current user has CREATE ANY TRIGGER privilege
  688. remark    (either directly or through a role).
  689. remark
  690.  
  691. create or replace view ALL_TRIGGER_COLS
  692. (TRIGGER_OWNER, TRIGGER_NAME, TABLE_OWNER, TABLE_NAME, COLUMN_NAME,
  693.     COLUMN_LIST, COLUMN_USAGE)
  694. as
  695. select /*+ ORDERED NOCOST */ u.name, o.name, u2.name, o2.name, c.name,
  696.    max(decode(tc.type,0,'YES','NO')) COLUMN_LIST,
  697.    decode(sum(decode(tc.type, 5,  1, -- one occurrence of new in
  698.                               6,  2, -- one occurrence of old in
  699.                               9,  4, -- one occurrence of new out
  700.                              10,  8, -- one occurrence of old out (impossible)
  701.                              13,  5, -- one occurrence of new in out
  702.                              14, 10, -- one occurrence of old in out (imp.)
  703.                               null)
  704.                 ), -- result in the following combinations across occurrences
  705.            1, 'NEW IN',
  706.            2, 'OLD IN',
  707.            3, 'NEW IN OLD IN',
  708.            4, 'NEW OUT',
  709.            5, 'NEW IN OUT',
  710.            6, 'NEW OUT OLD IN',
  711.            7, 'NEW IN OUT OLD IN',
  712.           'NONE')
  713. from sys.trigger$ t, sys.obj$ o, sys.user$ u, sys.user$ u2,
  714.      sys.col$ c, sys.obj$ o2, sys.triggercol$ tc
  715. where t.obj# = tc.obj#        -- find corresponding trigger definition
  716.   and o.obj# = t.obj#        --    and corresponding trigger name
  717.   and c.obj# = t.baseobject     -- and corresponding row in COL$ of
  718.   and c.col# = tc.col#        --    the referenced column
  719.   and o2.obj# = t.baseobject    -- and name of the table containing the trigger
  720.   and u2.user# = o2.owner#    -- and name of the user who owns the table
  721.   and u.user# = o.owner#    -- and name of user who owns the trigger
  722.   and
  723.   ( o.owner# = userenv('SCHEMAID') or o2.owner# = userenv('SCHEMAID')
  724.     or
  725.     exists    -- an enabled role (or current user) with CREATE ANY TRIGGER priv
  726.      ( select null from sys.sysauth$ sa    -- does 
  727.        where privilege# = -152             -- CREATE ANY TRIGGER privilege exist
  728.        and (grantee# in                    -- for current user or public
  729.             (select kzsrorol from x$kzsro) -- currently enabled role
  730.            )
  731.       )
  732.    )
  733. group by u.name, o.name, u2.name, o2.name, c.name
  734. /
  735. comment on table ALL_TRIGGER_COLS is
  736. 'Column usage in user''s triggers or in triggers on user''s tables'
  737. /
  738. comment on column ALL_TRIGGER_COLS.TRIGGER_OWNER is
  739. 'Owner of the trigger'
  740. /
  741. comment on column ALL_TRIGGER_COLS.TRIGGER_NAME is
  742. 'Name of the trigger'
  743. /
  744. comment on column ALL_TRIGGER_COLS.TABLE_OWNER is
  745. 'Owner of the table'
  746. /
  747. comment on column ALL_TRIGGER_COLS.TABLE_NAME is
  748. 'Name of the table on which the trigger is defined'
  749. /
  750. comment on column ALL_TRIGGER_COLS.COLUMN_NAME is
  751. 'Name of the column used in trigger definition'
  752. /
  753. comment on column ALL_TRIGGER_COLS.COLUMN_LIST is
  754. 'Is column specified in UPDATE OF clause?'
  755. /
  756. comment on column ALL_TRIGGER_COLS.COLUMN_USAGE is
  757. 'Usage of column within trigger body'
  758. /
  759. drop public synonym ALL_TRIGGER_COLS
  760. /
  761. create public synonym ALL_TRIGGER_COLS for ALL_TRIGGER_COLS
  762. /
  763. grant select on ALL_TRIGGER_COLS to public
  764. /
  765. remark
  766. remark    DBA_TRIGGER_COLS shows usage of columns in all triggers defined
  767. remark    by any user, on any user's table.
  768. remark
  769.  
  770. create or replace view DBA_TRIGGER_COLS
  771. (TRIGGER_OWNER, TRIGGER_NAME, TABLE_OWNER, TABLE_NAME, COLUMN_NAME,
  772.     COLUMN_LIST, COLUMN_USAGE)
  773. as
  774. select /*+ ORDERED NOCOST */ u.name, o.name, u2.name, o2.name, c.name,
  775.    max(decode(tc.type,0,'YES','NO')) COLUMN_LIST,
  776.    decode(sum(decode(tc.type, 5,  1, -- one occurrence of new in
  777.                               6,  2, -- one occurrence of old in
  778.                               9,  4, -- one occurrence of new out
  779.                              10,  8, -- one occurrence of old out (impossible)
  780.                              13,  5, -- one occurrence of new in out
  781.                              14, 10, -- one occurrence of old in out (imp.)
  782.                               null)
  783.                 ), -- result in the following combinations across occurrences
  784.            1, 'NEW IN',
  785.            2, 'OLD IN',
  786.            3, 'NEW IN OLD IN',
  787.            4, 'NEW OUT',
  788.            5, 'NEW IN OUT',
  789.            6, 'NEW OUT OLD IN',
  790.            7, 'NEW IN OUT OLD IN',
  791.           'NONE')
  792. from sys.trigger$ t, sys.obj$ o, sys.user$ u, sys.user$ u2,
  793.      sys.col$ c, sys.obj$ o2, sys.triggercol$ tc
  794. where t.obj# = tc.obj#        -- find corresponding trigger definition
  795.   and o.obj# = t.obj#        --    and corresponding trigger name
  796.   and c.obj# = t.baseobject     -- and corresponding row in COL$ of
  797.   and c.col# = tc.col#        --    the referenced column
  798.   and o2.obj# = t.baseobject    -- and name of the table containing the trigger
  799.   and u2.user# = o2.owner#    -- and name of the user who owns the table
  800.   and u.user# = o.owner#    -- and name of user who owns the trigger
  801. group by u.name, o.name, u2.name, o2.name, c.name
  802. /
  803. drop public synonym DBA_TRIGGER_COLS
  804. /
  805. create public synonym DBA_TRIGGER_COLS for DBA_TRIGGER_COLS
  806. /
  807. comment on table DBA_TRIGGER_COLS is
  808. 'Column usage in all triggers'
  809. /
  810. comment on column DBA_TRIGGER_COLS.TRIGGER_OWNER is
  811. 'Owner of the trigger'
  812. /
  813. comment on column DBA_TRIGGER_COLS.TRIGGER_NAME is
  814. 'Name of the trigger'
  815. /
  816. comment on column DBA_TRIGGER_COLS.TABLE_OWNER is
  817. 'Owner of the table'
  818. /
  819. comment on column DBA_TRIGGER_COLS.TABLE_NAME is
  820. 'Name of the table on which the trigger is defined'
  821. /
  822. comment on column DBA_TRIGGER_COLS.COLUMN_NAME is
  823. 'Name of the column used in trigger definition'
  824. /
  825. comment on column DBA_TRIGGER_COLS.COLUMN_LIST is
  826. 'Is column specified in UPDATE OF clause?'
  827. /
  828. comment on column DBA_TRIGGER_COLS.COLUMN_USAGE is
  829. 'Usage of column within trigger body'
  830. /
  831.  
  832. remark
  833. remark    FAMILY "DEPENDENCIES"
  834. remark    Dependencies between database objects
  835. remark
  836.  
  837. create or replace view USER_DEPENDENCIES
  838.   (NAME, TYPE, REFERENCED_OWNER, REFERENCED_NAME,
  839.    REFERENCED_TYPE, REFERENCED_LINK_NAME)
  840. as
  841. select o.name,
  842.        decode(o.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  843.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  844.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  845.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  846.        decode(po.linkname, null, pu.name, po.remoteowner), po.name,
  847.        decode(po.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  848.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  849.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  850.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  851.        po.linkname
  852. from sys.obj$ o, sys.obj$ po, sys.dependency$ d, sys.user$ pu
  853. where o.obj# = d.d_obj#
  854.   and po.obj# = d.p_obj#
  855.   and po.owner# = pu.user#
  856.   and o.owner# = userenv('SCHEMAID')
  857. /
  858. comment on table USER_DEPENDENCIES is
  859. 'Dependencies to and from a users objects'
  860. /
  861. comment on column USER_DEPENDENCIES.NAME is
  862. 'Name of the object'
  863. /
  864. comment on column USER_DEPENDENCIES.TYPE is
  865. 'Type of the object'
  866. /
  867. comment on column USER_DEPENDENCIES.REFERENCED_OWNER is
  868. 'Owner of referenced object (remote owner if remote object)'
  869. /
  870. comment on column USER_DEPENDENCIES.REFERENCED_NAME is
  871. 'Name of referenced object'
  872. /
  873. comment on column USER_DEPENDENCIES.REFERENCED_TYPE is
  874. 'Type of referenced object'
  875. /
  876. comment on column USER_DEPENDENCIES.REFERENCED_LINK_NAME is
  877. 'Name of dblink if this is a remote object'
  878. /
  879. drop public synonym USER_DEPENDENCIES
  880. /
  881. create public synonym USER_DEPENDENCIES for USER_DEPENDENCIES
  882. /
  883. grant select on USER_DEPENDENCIES to public with grant option
  884. /
  885.  
  886. create or replace view ALL_DEPENDENCIES
  887.   (OWNER, NAME, TYPE, REFERENCED_OWNER, REFERENCED_NAME,
  888.    REFERENCED_TYPE, REFERENCED_LINK_NAME)
  889. as
  890. select u.name, o.name,
  891.        decode(o.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  892.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  893.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  894.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  895.        decode(po.linkname, null, pu.name, po.remoteowner), po.name,
  896.        decode(po.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  897.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  898.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  899.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  900.        po.linkname
  901. from sys.obj$ o, sys.obj$ po, sys.dependency$ d, sys.user$ u, sys.user$ pu
  902. where o.obj# = d.d_obj#
  903.   and o.owner# = u.user#
  904.   and po.obj# = d.p_obj#
  905.   and po.owner# = pu.user#
  906.   and
  907.   (
  908.     o.owner# in (userenv('SCHEMAID'), 1 /* PUBLIC */)
  909.     or
  910.     (
  911.       (
  912.          (
  913.           (o.type = 7 or o.type = 8 or o.type = 9)
  914.           and
  915.           o.obj# in (select obj# from sys.objauth$
  916.                      where grantee# in (select kzsrorol from x$kzsro)
  917.                        and privilege#  = 12 /* EXECUTE */)
  918.         )
  919.         or
  920.         (
  921.           o.type = 4
  922.           and
  923.           o.obj# in (select obj# from sys.objauth$
  924.                      where grantee# in (select kzsrorol from x$kzsro)
  925.                        and privilege# in (3 /* DELETE */,   6 /* INSERT */,
  926.                                             7 /* LOCK */,     9 /* SELECT */,
  927.                                           10 /* UPDATE */))
  928.         )
  929.         or
  930.         exists
  931.         (
  932.           select null from sys.sysauth$
  933.           where grantee# in (select kzsrorol from x$kzsro)
  934.           and
  935.           (
  936.             (
  937.               /* procedure */
  938.               (o.type = 7 or o.type = 8 or o.type = 9)
  939.               and
  940.               (
  941.                 privilege# = -144 /* EXECUTE ANY PROCEDURE */
  942.                 or
  943.                 privilege# = -141 /* CREATE ANY PROCEDURE */
  944.               )
  945.             )
  946.         or
  947.             (
  948.               /* package body */
  949.               o.type = 11 and
  950.               privilege# = -141 /* CREATE ANY PROCEDURE */
  951.             )
  952.             or
  953.             (
  954.               /* view */
  955.               o.type = 4
  956.               and
  957.               (
  958.                 privilege# in     ( -91 /* CREATE ANY VIEW */,
  959.                     -45 /* LOCK ANY TABLE */,
  960.                                     -47 /* SELECT ANY TABLE */,
  961.                                     -48 /* INSERT ANY TABLE */,
  962.                                     -49 /* UPDATE ANY TABLE */,
  963.                                     -50 /* DELETE ANY TABLE */)
  964.               )
  965.             )
  966.           )
  967.         )
  968.       )
  969.     )
  970.     /* don't worry about tables, sequences, synonyms since they cannot */
  971.     /* depend on anything */
  972.   )
  973. /
  974. comment on table ALL_DEPENDENCIES is
  975. 'Dependencies to and from objects accessible to the user'
  976. /
  977. comment on column ALL_DEPENDENCIES.OWNER is
  978. 'Owner of the object'
  979. /
  980. comment on column ALL_DEPENDENCIES.NAME is
  981. 'Name of the object'
  982. /
  983. comment on column ALL_DEPENDENCIES.TYPE is
  984. 'Type of the object'
  985. /
  986. comment on column ALL_DEPENDENCIES.REFERENCED_OWNER is
  987. 'Owner of referenced object (remote owner if remote object)'
  988. /
  989. comment on column ALL_DEPENDENCIES.REFERENCED_NAME is
  990. 'Name of referenced object'
  991. /
  992. comment on column ALL_DEPENDENCIES.REFERENCED_TYPE is
  993. 'Type of referenced object'
  994. /
  995. comment on column ALL_DEPENDENCIES.REFERENCED_LINK_NAME is
  996. 'Name of dblink if this is a remote object'
  997. /
  998. drop public synonym ALL_DEPENDENCIES
  999. /
  1000. create public synonym ALL_DEPENDENCIES for ALL_DEPENDENCIES
  1001. /
  1002. grant select on ALL_DEPENDENCIES to public with grant option
  1003. /
  1004.  
  1005. create or replace view DBA_DEPENDENCIES
  1006.   (OWNER, NAME, TYPE, REFERENCED_OWNER, REFERENCED_NAME,
  1007.    REFERENCED_TYPE, REFERENCED_LINK_NAME)
  1008. as
  1009. select u.name, o.name,
  1010.        decode(o.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  1011.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  1012.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  1013.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  1014.        decode(po.linkname, null, pu.name, po.remoteowner), po.name,
  1015.        decode(po.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  1016.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  1017.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  1018.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  1019.        po.linkname
  1020. from sys.obj$ o, sys.obj$ po, sys.dependency$ d, sys.user$ u, sys.user$ pu
  1021. where o.obj# = d.d_obj#
  1022.   and o.owner# = u.user#
  1023.   and po.obj# = d.p_obj#
  1024.   and po.owner# = pu.user#
  1025. /
  1026. drop public synonym DBA_DEPENDENCIES
  1027. /
  1028. create public synonym DBA_DEPENDENCIES for DBA_DEPENDENCIES
  1029. /
  1030. comment on table DBA_DEPENDENCIES is
  1031. 'Dependencies to and from objects'
  1032. /
  1033. comment on column DBA_DEPENDENCIES.OWNER is
  1034. 'Owner of the object'
  1035. /
  1036. comment on column DBA_DEPENDENCIES.NAME is
  1037. 'Name of the object'
  1038. /
  1039. comment on column DBA_DEPENDENCIES.TYPE is
  1040. 'Type of the object'
  1041. /
  1042. comment on column DBA_DEPENDENCIES.REFERENCED_OWNER is
  1043. 'Owner of referenced object (remote owner if remote object)'
  1044. /
  1045. comment on column DBA_DEPENDENCIES.REFERENCED_NAME is
  1046. 'Name of referenced object'
  1047. /
  1048. comment on column DBA_DEPENDENCIES.REFERENCED_TYPE is
  1049. 'Type of referenced object'
  1050. /
  1051. comment on column DBA_DEPENDENCIES.REFERENCED_LINK_NAME is
  1052. 'Name of dblink if this is a remote object'
  1053. /
  1054.  
  1055.  
  1056. remark
  1057. remark    PUBLIC_DEPENDENCIES
  1058. remark    Hierarchic dependency information by object number
  1059. remark
  1060.  
  1061. create or replace view PUBLIC_DEPENDENCY
  1062.   (OBJECT_ID, REFERENCED_OBJECT_ID)
  1063. as
  1064. select d.d_obj#, d.p_obj# from dependency$ d
  1065. /
  1066. comment on table PUBLIC_DEPENDENCY is
  1067. 'Dependencies to and from objects, by object number'
  1068. /
  1069. comment on column PUBLIC_DEPENDENCY.OBJECT_ID is
  1070. 'Object number'
  1071. /
  1072. comment on column PUBLIC_DEPENDENCY.REFERENCED_OBJECT_ID is
  1073. 'The referenced (parent) object'
  1074. /
  1075. drop public synonym PUBLIC_DEPENDENCY
  1076. /
  1077. create public synonym PUBLIC_DEPENDENCY for PUBLIC_DEPENDENCY
  1078. /
  1079. grant select on PUBLIC_DEPENDENCY to public with grant option
  1080. /
  1081.  
  1082. remark
  1083. remark    FAMILY "OBJECT_SIZE"
  1084. remark    Sizes of pl/sql items.
  1085. remark       source_size - this part must be in memory when the object
  1086. remark                     is compiled, or dynamically recompiled
  1087. remark       parsed_size - this part must be in memory when an object that
  1088. remark                     references this object is being compiled
  1089. remark       code_size   - this part must be in memory when this object
  1090. remark                     is executing
  1091. remark       error_size  - this part exists if the object has compilation
  1092. remark                     errors and need only be in memory until the
  1093. remark                     compilation completes
  1094. remark    Tables and views will also appear if they were ever referenced by
  1095. remark    a pl/sql object.  They will only have a parsed component.
  1096. remark
  1097.  
  1098. remark Define some of the supporting views
  1099.  
  1100. create or replace view CODE_PIECES
  1101. (OBJ#, BYTES)
  1102. as
  1103.   select i.obj#, i.length
  1104.   from sys.idl_ub1$ i
  1105.   where i.part in (1,2)
  1106. union all
  1107.   select i.obj#, i.length
  1108.   from sys.idl_ub2$ i
  1109.   where i.part in (1,2)
  1110. union all
  1111.   select i.obj#, i.length
  1112.   from sys.idl_sb4$ i
  1113.   where i.part in (1,2)
  1114. union all
  1115.   select i.obj#, i.length
  1116.   from sys.idl_char$ i
  1117.   where i.part in (1,2)
  1118. /
  1119.  
  1120. create or replace view CODE_SIZE
  1121. (OBJ#, BYTES)
  1122. as
  1123.   select c.obj#, sum(c.bytes)
  1124.   from sys.code_pieces c
  1125.   group by c.obj#
  1126. /
  1127.  
  1128. create or replace view PARSED_PIECES
  1129. (OBJ#, BYTES)
  1130. as
  1131.   select i.obj#, i.length
  1132.   from sys.idl_ub1$ i
  1133.   where i.part = 0
  1134. union all
  1135.   select i.obj#, i.length
  1136.   from sys.idl_ub2$ i
  1137.   where i.part = 0
  1138. union all
  1139.   select i.obj#, i.length
  1140.   from sys.idl_sb4$ i
  1141.   where i.part = 0
  1142. union all
  1143.   select i.obj#, i.length
  1144.   from sys.idl_char$ i
  1145.   where i.part = 0
  1146. /
  1147.  
  1148. create or replace view PARSED_SIZE
  1149. (OBJ#, BYTES)
  1150. as
  1151.   select c.obj#, sum(c.bytes)
  1152.   from sys.parsed_pieces c
  1153.   group by c.obj#
  1154. /
  1155.  
  1156. create or replace view SOURCE_SIZE
  1157. (OBJ#, BYTES)
  1158. as
  1159.   select s.obj#, sum(length(s.source))
  1160.   from sys.source$ s
  1161.   group by s.obj#
  1162. /
  1163.  
  1164. create or replace view ERROR_SIZE
  1165. (OBJ#, BYTES)
  1166. as
  1167.   select e.obj#, sum(e.textlength)
  1168.   from sys.error$ e
  1169.   group by e.obj#
  1170. /
  1171.  
  1172. create or replace view DBA_OBJECT_SIZE
  1173. (OWNER, NAME, TYPE, SOURCE_SIZE, PARSED_SIZE, CODE_SIZE, ERROR_SIZE)
  1174. as
  1175.   select u.name, o.name,
  1176.   decode(o.type, 2, 'TABLE', 4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
  1177.     7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE', 11, 'PACKAGE BODY',
  1178.     'UNDEFINED'),
  1179.   nvl(s.bytes,0), nvl(p.bytes,0), nvl(c.bytes,0), nvl(e.bytes,0)
  1180.   from sys.obj$ o, sys.user$ u,
  1181.     sys.source_size s, sys.parsed_size p, sys.code_size c, sys.error_size e
  1182.   where o.type in (2, 4, 5, 6, 7, 8, 9, 11)
  1183.     and o.owner# = u.user#
  1184.     and o.obj# = s.obj# (+)
  1185.     and o.obj# = p.obj# (+)
  1186.     and o.obj# = c.obj# (+)
  1187.     and o.obj# = e.obj# (+)
  1188.     and nvl(s.bytes,0) + nvl(p.bytes,0) + nvl(c.bytes,0) + nvl(e.bytes,0) > 0
  1189. /
  1190. drop public synonym DBA_OBJECT_SIZE
  1191. /
  1192. create public synonym DBA_OBJECT_SIZE for DBA_OBJECT_SIZE
  1193. /
  1194. comment on table DBA_OBJECT_SIZE is
  1195. 'Sizes, in bytes, of various pl/sql objects'
  1196. /
  1197. comment on column DBA_OBJECT_SIZE.OWNER is
  1198. 'Owner of the object'
  1199. /
  1200. comment on column DBA_OBJECT_SIZE.NAME is
  1201. 'Name of the object'
  1202. /
  1203. comment on column DBA_OBJECT_SIZE.TYPE is
  1204. 'Type of the object: "TABLE", "VIEW", "SYNONYM", "SEQUENCE", "PROCEDURE",
  1205. "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  1206. /
  1207. comment on column DBA_OBJECT_SIZE.SOURCE_SIZE is
  1208. 'Size of the source, in bytes.  Must be in memory during compilation, or
  1209. dynamic recompilation'
  1210. /
  1211. comment on column DBA_OBJECT_SIZE.PARSED_SIZE is
  1212. 'Size of the parsed form of the object, in bytes.  Must be in memory when
  1213. an object is being compiled that references this object'
  1214. /
  1215. comment on column DBA_OBJECT_SIZE.CODE_SIZE is
  1216. 'Code size, in bytes.  Must be in memory when this object is executing'
  1217. /
  1218. comment on column DBA_OBJECT_SIZE.ERROR_SIZE is
  1219. 'Size of error messages, in bytes.  In memory during the compilation of the object when there are compilation errors'
  1220. /
  1221.  
  1222. create or replace view USER_OBJECT_SIZE
  1223. (NAME, TYPE, SOURCE_SIZE, PARSED_SIZE, CODE_SIZE, ERROR_SIZE)
  1224. as
  1225.   select o.name,
  1226.   decode(o.type, 2, 'TABLE', 4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
  1227.     7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE', 11, 'PACKAGE BODY',
  1228.     'UNDEFINED'),
  1229.   nvl(s.bytes,0), nvl(p.bytes,0), nvl(c.bytes,0), nvl(e.bytes,0)
  1230.   from sys.obj$ o,
  1231.     sys.source_size s, sys.parsed_size p, sys.code_size c, sys.error_size e
  1232.   where o.type in (2, 4, 5, 6, 7, 8, 9, 11)
  1233.     and o.owner# = userenv('SCHEMAID')
  1234.     and o.obj# = s.obj# (+)
  1235.     and o.obj# = p.obj# (+)
  1236.     and o.obj# = c.obj# (+)
  1237.     and o.obj# = e.obj# (+)
  1238.     and nvl(s.bytes,0) + nvl(p.bytes,0) + nvl(c.bytes,0) + nvl(e.bytes,0) > 0
  1239. /
  1240. comment on table USER_OBJECT_SIZE is
  1241. 'Sizes, in bytes, of various pl/sql objects'
  1242. /
  1243. comment on column USER_OBJECT_SIZE.NAME is
  1244. 'Name of the object'
  1245. /
  1246. comment on column USER_OBJECT_SIZE.TYPE is
  1247. 'Type of the object: "TABLE", "VIEW", "SYNONYM", "SEQUENCE", "PROCEDURE",
  1248. "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  1249. /
  1250. comment on column USER_OBJECT_SIZE.SOURCE_SIZE is
  1251. 'Size of the source, in bytes.  Must be in memory during compilation, or
  1252. dynamic recompilation'
  1253. /
  1254. comment on column USER_OBJECT_SIZE.PARSED_SIZE is
  1255. 'Size of the parsed form of the object, in bytes.  Must be in memory when
  1256. an object is being compiled that references this object'
  1257. /
  1258. comment on column USER_OBJECT_SIZE.CODE_SIZE is
  1259. 'Code size, in bytes.  Must be in memory when this object is executing'
  1260. /
  1261. comment on column USER_OBJECT_SIZE.ERROR_SIZE is
  1262. 'Size of error messages, in bytes.  In memory during the compilation of the object when there are compilation errors'
  1263. /
  1264. drop public synonym USER_OBJECT_SIZE
  1265. /
  1266. create public synonym USER_OBJECT_SIZE for USER_OBJECT_SIZE
  1267. /
  1268. grant select on USER_OBJECT_SIZE to public with grant option
  1269. /
  1270.